package com.ranlen.ems_vue.service.serviceImpl;

import com.ranlen.ems_vue.dao.EmpDao;
import com.ranlen.ems_vue.dao.UserDao;
import com.ranlen.ems_vue.entity.*;
import com.ranlen.ems_vue.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EmpServiceImpl implements EmpService {

    private EmpDao empDao;

    @Autowired
    public EmpServiceImpl(EmpDao empDao) {
        this.empDao = empDao;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Emp> findAll() {
        return empDao.findAll();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Emp> findAll2(String id) {
        return empDao.findAll2(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public void save(Emp emp) {
        empDao.save(emp);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public void save_relation(User_Emp user_emp) {
        empDao.save_relation(user_emp);
    }

    @Override
    public void delete(String id) {
        empDao.delete(id);
    }

    @Override
    public void delete_relation(String e_id) {
        empDao.delete_relation(e_id);
    }

    @Override
    public Emp findEmpById(String id) {
        return empDao.findEmpById(id);
    }

    @Override
    public void update(Emp emp) {
        empDao.update(emp);
    }

    @Override
    public List<Salary> findSalaryAll(String id) {
        return empDao.selectSalary(id);
    }

    @Override
    public Money findMoneyAll(String id) {
        return empDao.selectMoney(id);
    }

    @Override
    public List<Kaoqin> findKaoqinAll(String id) {
        return empDao.selectKaoqin(id);
    }

    @Override
    public Salary findSalaryOne(String id) {
        return empDao.findSalaryById(id);
    }

    @Override
    public void updateSalary(Salary salary) {
        Emp emp = new Emp();
        emp.setSalary(String.valueOf(salary.getAllowance()+salary.getBasic()+salary.getOvertime()));
        emp.setId(salary.getE_id());
        empDao.updateSalary(salary);
        empDao.updateEmpSalary(emp);
    }

    @Override
    public void updateMoney(Money money) {
        empDao.updateMoney(money);
    }

    @Override
    public void updateKaoqin(Kaoqin kaoqin) {
        empDao.updateKaoqin(kaoqin);
    }

    @Override
    public Kaoqin findKaoqinOne(String id) {
        return empDao.findKaoqinById(id);
    }
}
